class Singletonlazy{
    volatile private static Singletonlazy instance=null;
    public static Singletonlazy get(){
        //判断是否要加锁，如果已经有对象了就不必加锁，此时线程安全
        if(instance==null){
            synchronized (Singletonlazy.class){
                //判断是否要实例化一个对象
                if(instance==null){
                    instance=new Singletonlazy();
                }
            }
        }
        return instance;
    }
    private Singletonlazy(){}
}

//通过懒汉模式实现单例模式
public class demo04 {
    public static void main(String[] args) {
        Singletonlazy s1=Singletonlazy.get();
        Singletonlazy s2=Singletonlazy.get();
        System.out.println(s1==s2);
    }
}
